package com.fourinone.bean;

import com.fourinone.core.MasterBase;
import com.fourinone.core.PoolExactor;
import com.fourinone.utils.Setting;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 * @author szper
 * @version 1.0
 * @date 2019/10/20 22:58
 */
public class ServiceBean extends PoolExactor {
    final static void putBean(String TPYFWYM, boolean TPYRZDY, int TPYDK, String rmname, MasterBase paobj) {
        if (TPYFWYM != null)
            System.setProperty(Setting.getYMMZ(), TPYFWYM);
        if (TPYRZDY)
            System.setProperty(Setting.getRZDY(), "true");
        try {
            LocateRegistry.getRegistry(TPYDK).list();
        } catch (Exception ex) {
            try {
                UnicastRemoteObject.exportObject(paobj, 0);
                Registry rgsty = LocateRegistry.createRegistry(TPYDK);//getRegistry(TPYDK);
                rgsty.rebind(rmname, paobj);
            } catch (Exception e) {
                System.out.println("[ObjectService] [regObject] [Error Exception:]" + e.toString());
            }
        }
    }
}
